# A basic singleton
#
# State does not inherited by child class

class Singleton(object):
    
    def __new__(cls):
        if not hasattr(cls, 'instance'):
            cls.instance = super(Singleton, cls).__new__(cls)
        return cls.instance

class ChildSingleton(Singleton):
    pass

class Borg(object):

    _shared_state = {}
    def __new__(cls, *args, **kwargs):
        obj = super(Borg, cls).__new__(cls, *args, **kwargs)
        print obj._shared_state
        obj.__dict__ = obj._shared_state
        return obj

class ChildBorg(Borg): 
    pass

x = Borg()
x.name = 'Cornell'

y = ChildBorg()
y.name = 'Jane'


print "x.name = ", x.name
print "y.name = ", y.name

print x is y
